package com.weighttracker.android;

import com.bappi.custom.activities.CustomActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Tab3Activity21 extends CustomActivity{
	
	private EditText fatField,carbField,fiberField,proteinField,resultFiled;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.layout_tab_3_screen_21);
			fatField = (EditText)findViewById(R.id.fat_field);
			carbField = (EditText)findViewById(R.id.cabs_field);
			fiberField = (EditText)findViewById(R.id.fiber_field);
			proteinField = (EditText)findViewById(R.id.protein_field);
			resultFiled = (EditText)findViewById(R.id.result_field);
			findViewById(R.id.button_back).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					finish();
				}
			});
			findViewById(R.id.button_clear).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					fatField.setText("");
					carbField.setText("");
					fiberField.setText("");
					proteinField.setText("");
					resultFiled.setText("");
				}
			});
			findViewById(R.id.button_calculate).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					double fat = 0.0F;
					double carbs = 0.0F;
					double fiber = 0.0F;
					double protein = 0.0F;
					String text;
					try {
						text = fatField.getText().toString();
						if(text.length()>0){
							fat = Float.parseFloat(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					try {
						text = carbField.getText().toString();
						if(text.length()>0){
							carbs = Float.parseFloat(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					try {
						text = fiberField.getText().toString();
						if(text.length()>0){
							fiber = Float.parseFloat(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					try {
						
						text = proteinField.getText().toString();
						if(text.length()>0){
							protein = Float.parseFloat(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					double value = (protein / 10.9375) + (carbs / 9.2105) + (fat / 3.8889) - (fiber /12.5);
//					resultFiled.setText(Long.toString((long)Math.floor(value)));
					resultFiled.setText(Long.toString(Math.round(value)));
					
				}
			});
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}
